import axios from "axios";
import store from "@/store"

const request = axios.create({
    baseURL: "http://localhost:8888",
    timeout: 5000,
})

request.interceptors.request.use(config => {
    config.headers.token = store.getters.getToken();
    console.log('headers',config.headers)
    return config;
});

request.interceptors.response.use(function (response){
    let code = response.data.code
    if(code >= 400 && code <= 405){
        response.data.msg = "用户认证失败，请重新登录";
        localStorage.removeItem("token");
    }
    console.log('response',response);
    return response;
},function (error){
    console.log(error);
    return Promise.reject(error);
});

export default request;
